*-------------------------------------------------------------------------------
*       POLITICIANS AND TAX POLICY: The Role of Preferences and Beliefs
*-------------------------------------------------------------------------------
*-------------------------------------------------------------------------------
* Description: this do-file manipulates and constructs all the variables that 
* are based on non-proprietary public data
*-------------------------------------------------------------------------------

clear all
global clear
set more off
graph set window fontface "Times New Roman"

*Setting directories
********************************************************************************
if `"`c(os)'"' == "MacOSX"	global path   `"/users/`c(username)'/Dropbox/Research info & policy/Taxpolicy_followup/Data and CodeNTJ_forpublic"'
if `"`c(os)'"' == "Windows"	global path   `"C:/Users/`c(username)'/Dropbox/Research info & policy/Taxpolicy_followup/Data and CodeNTJ_forpublic"'

global rawdata 		"${path}/raw data" 
********************************************************************************

***********************************
********** CENSUS DATA ************
***********************************
clear all
import excel "${rawdata}/census data/Atlas 2013_municipal, estadual e Brasil.xlsx", sheet("MUN 91-00-10") firstrow
keep if ANO==2010
* we keep only the variables that we use in the analysis
keep Codmun6 T_SUPER25M PMPOB GINI RDPC 
rename Codmun6 cod_ibge
rename T_SUPER25M college_population
rename PMPOB poverty
rename GINI gini_index
rename RDPC income_pc_monthly

foreach var in "cod_ibge" "college_population" "poverty" "gini_index" "income_pc_monthly" {
label var `var' ""
}

label var cod_ibge "Municipality official id" // Source: IBGE
label var college_population "College Population" // Source: Atlas do Densenvolvimento Humano no Brasil (Census 2010)
label var poverty "Poverty" // Source: Atlas do Densenvolvimento Humano no Brasil (Census 2010)
label var gini_index "Gini" // Source: Atlas do Densenvolvimento Humano no Brasil (Census 2010)
label var income_pc_monthly "Per Capita Income" // Source: Atlas do Densenvolvimento Humano no Brasil (Census 2010)

save "${rawdata}/clean data/census.dta", replace     

***********************************
******** POPULATION DATA **********
***********************************
clear all
import excel "${rawdata}/population/estimativa_dou_2016_20160913.xlsx", sheet("Municípios") cellrange(A3:E5573) firstrow

* There are 7 municipalities with "notes" in the population number. We proceed to eliminate those notes
replace POPULAÇÃOESTIMADA="41487" if NOMEDOMUNICÍPIO=="Jacareacanga"
replace POPULAÇÃOESTIMADA="61621" if NOMEDOMUNICÍPIO=="Barreirinhas"
replace POPULAÇÃOESTIMADA="25192" if NOMEDOMUNICÍPIO=="Santa Quitéria do Maranhão"
replace POPULAÇÃOESTIMADA="32629" if NOMEDOMUNICÍPIO=="Urbano Santos"
replace POPULAÇÃOESTIMADA="36789" if NOMEDOMUNICÍPIO=="Morro do Chapéu"
replace POPULAÇÃOESTIMADA="25002" if NOMEDOMUNICÍPIO=="Piritiba"
replace POPULAÇÃOESTIMADA="17855" if NOMEDOMUNICÍPIO=="Tapiramutá"

* we adjust the official municipality id
egen cod_ibge=concat(CODUF CODMUNIC)
replace cod_ibge = substr(cod_ibge, 1, 6)
destring cod_ibge, replace

destring POPULAÇÃOESTIMADA, gen(popul_2016)
label var popul_2016 ""

rename UF state_uf
label var state_uf ""

* we define a regional south region (south + south east + midwest states)
gen big_south=0 if state_uf!=""
foreach state in "RS" "SC" "PR" "SP" "MG" "RJ" "ES" "GO" "MT" "MS"{

replace big_south =1 if state_uf=="`state'"
}

* we keep only the variables that we use in the analysis
order cod_ibge state_uf popul_2016 big_south
keep cod_ibge state_uf popul_2016 big_south

label var cod_ibge "Municipality official id" // Source: IBGE
label var state_uf "State code"
label var popul_2016 "Population" // Source: IBGE 2016
label var big_south "Big South" // Source: Own based on IBGE 

save "${rawdata}/clean data/population.dta", replace 


***********************************
********* ELECTORAL DATA **********
***********************************

*** Vote Margin (data accessed in May 2020) ***
clear all

foreach state in AC AL AM AP BA CE ES GO MA MG MS MT PA PB PE PI PR RJ RN RO RR RS SC SE SP TO {

import delimited "${rawdata}/vote margin/votacao_candidato_munzona_2016_`state'.csv", delimiter(";") clear

* first round
keep if nr_turno==1

* mayors
keep if cd_cargo==11

* municipal-candidate level
collapse (sum) qt_votos , by(nr_cand cd_mun nm_mun cd_sit_ sg_uf )

* most votes first
gsort cd_mun -qt_votos +cd_sit_tot_turno

* difference only for elected to runner-up
bysort cd_mun: gen votediff = qt_votos[_n] - qt_votos[_n+1] if cd_sit==1

* counting candidates and keeping difference on municipal level data
collapse (count) nr_cand (max) votediff (sum) qt_votos, by(cd_mun nm_mun sg_uf)

rename nr_cand ncandidates

* this vote margin does not count null and blank votes on the denominator
* only votes cast to a specific candidate
gen vtmargin_mayor = votediff/qt

save "${rawdata}/vote margin/temp/vtmdata`state'16.dta", replace

}

* appending data
use "${rawdata}/vote margin/temp/vtmdataAC16.dta"

foreach state in AL AM AP BA CE ES GO MA MG MS MT PA PB PE PI PR RJ RN RO RR RS SC SE SP TO {

append using "${rawdata}/vote margin/temp/vtmdata`state'16.dta"

}

rename cd_mun id_municipio_tse
* we merge the official municipality id
preserve 
import delimited "${rawdata}/municipalities/diretorio_municipios.csv", clear
save "${rawdata}/municipalities/officialids.dta", replace
restore
merge 1:1 id_municipio_tse using "${rawdata}/municipalities/officialids.dta", keepusing(id_municipio)
rename id_municipio cod_ibge
replace cod_ibge = floor(cod_ibge/10)
order cod_ibge vtmargin_mayor
* we keep only the variables that we use in the analysis
keep cod_ibge vtmargin_mayor

label var cod_ibge "Municipality official id" // Source: IBGE
label var vtmargin_mayor "Electoral Margin Victory - Mayor" // Source: Tribunal Superior Eleitoral (Elections 2016)

save "${rawdata}/clean data/vote_margin.dta", replace


*** Mayors Characteristics Policy-Adoption Experiment (data accessed in October 2016) ***
clear all
import excel "${rawdata}/mayors data/Prefeitos_Eleitos.xlsx", sheet("Sheet1") cellrange(A1:AV5500) firstrow

* we keep only the variables that we use in the analysis (or data cleaning)
rename SIGLA_UE id_tse
rename NOME_CANDIDATO name_mayor_2016
rename Nome2012 name_mayor_2012
rename SIGLA_PARTIDO party_mayor
rename P cpf_mayor // the cpf is a unique official identifier of an individual
rename IDADE_DATA_ELEICAO age_mayor
rename CODIGO_SEXO code_gender_mayor
rename DESCRICAO_SEXO gender_mayor
rename COD_GRAU_INSTRUCAO code_educ_mayor
rename DESCRICAO_GRAU_INSTRUCAO educ_mayor

keep id_tse name_mayor_2016 name_mayor_2012 party_mayor cpf_mayor age_mayor code_gender_mayor gender_mayor code_educ_mayor educ_mayor

foreach var in "id_tse" "name_mayor_2016" "name_mayor_2012" "party_mayor" "cpf_mayor" "age_mayor" ///
"code_gender_mayor" "gender_mayor" "code_educ_mayor" "educ_mayor" {

label var `var' ""

}

rename id_tse id_municipio_tse
* we merge the official municipality id
merge 1:1 id_municipio_tse using "${rawdata}/municipalities/officialids.dta", keepusing(id_municipio)
drop _merge
rename id_municipio cod_ibge
replace cod_ibge = floor(cod_ibge/10)

// there are 71 municipalities that did not have data at the time we collected in 2016 (5499)
// we complete the data exclusively for our sample municipalities (8 munic) based on public information retrieved from google searches (5507/5570)
replace name_mayor_2016="EDIVALDO DE HOLANDA BRAGA JUNIOR" if cod_ibge==211130
replace party_mayor="PDT" if cod_ibge==211130
replace age_mayor=38 if cod_ibge==211130
replace code_gender_mayor=2 if cod_ibge==211130
replace code_educ_mayor=8 if cod_ibge==211130
replace cpf_mayor=40756459320 if cod_ibge==211130
replace name_mayor_2016="GERALDO LUZIA DE OLIVEIRA JUNIOR" if cod_ibge==320130
replace party_mayor="PPS" if cod_ibge==320130
replace age_mayor=46 if cod_ibge==320130
replace code_gender_mayor=2 if cod_ibge==320130
replace code_educ_mayor=8 if cod_ibge==320130
replace cpf_mayor=1519986718 if cod_ibge==320130
replace name_mayor_2016="JOSÉ SLOBODA" if cod_ibge==411200
replace party_mayor="PHS" if cod_ibge==411200
replace age_mayor=50 if cod_ibge==411200
replace code_gender_mayor=2 if cod_ibge==411200
replace code_educ_mayor=6 if cod_ibge==411200
replace cpf_mayor=52933300982 if cod_ibge==411200
replace name_mayor_2016="MARCELO RANGEL CRUZ DE OLIVEIRA" if cod_ibge==411990
replace party_mayor="PPS" if cod_ibge==411990
replace age_mayor=46 if cod_ibge==411990
replace code_gender_mayor=2 if cod_ibge==411990
replace code_educ_mayor=8 if cod_ibge==411990
replace cpf_mayor=72640898949 if cod_ibge==411990
replace name_mayor_2016="ROGERIO FELINI FACHINETTO" if cod_ibge==430140
replace party_mayor="PDT" if cod_ibge==430140
replace age_mayor=50 if cod_ibge==430140
replace code_gender_mayor=2 if cod_ibge==430140
replace code_educ_mayor=7 if cod_ibge==430140
replace cpf_mayor=48685089034 if cod_ibge==430140
replace name_mayor_2016="IVETE BEATRIZ ZAMARCHI LUCHEZI" if cod_ibge==430990
replace party_mayor="PMDB" if cod_ibge==430990
replace age_mayor=59 if cod_ibge==430990
replace code_gender_mayor=4 if cod_ibge==430990
replace code_educ_mayor=8 if cod_ibge==430990
replace cpf_mayor=32512155072 if cod_ibge==430990
replace name_mayor_2016="DIEGO PICUCHA" if cod_ibge==431405
replace party_mayor="PDT" if cod_ibge==431405
replace age_mayor=32 if cod_ibge==431405
replace code_gender_mayor=2 if cod_ibge==431405
replace code_educ_mayor=8 if cod_ibge==431405
replace cpf_mayor=. if cod_ibge==431405
replace name_mayor_2016="CLAUDIOMIRO GAMST ROBINSON" if cod_ibge==431645
replace party_mayor="PDT" if cod_ibge==431645
replace age_mayor=49 if cod_ibge==431645
replace code_gender_mayor=2 if cod_ibge==431645
replace code_educ_mayor=3 if cod_ibge==431645
replace cpf_mayor=51137313072 if cod_ibge==431645

* we define male gender, college completion and leftist party
gen male_mayor=1 if code_gender_mayor==2
replace male_mayor=0 if code_gender_mayor==4

gen college_mayor=1 if code_educ_mayor==8
replace college_mayor=0 if code_educ_mayor!=8&code_educ_mayor!=.

gen party_left_mayor=0 if party_mayor!=""
replace party_left_mayor=1 if party_mayor=="PC do B" | party_mayor=="PDT" ///
| party_mayor=="PMB" | party_mayor=="PMN" | party_mayor=="PPS" | ///
party_mayor=="PSB" | party_mayor=="PSD" | party_mayor=="PSOL" | ///
party_mayor=="PT" | party_mayor=="REDE" | party_mayor=="SD" | ///
party_mayor=="PT do B"

order cod_ibge id_municipio_tse name_mayor_2016 male_mayor age_mayor college_mayor party_left_mayor party_mayor cpf_mayor name_mayor_2012

save "${rawdata}/mayors data/temp/policyexperiment_mayor_char_temp.dta", replace 

*** Term in office (have to clean 2012 election data - data accessed October 2016) ***
clear all

foreach state in AC AL AM AP BA CE ES GO MA MG MS MT PA PB PE PI PR RJ RN RO RR RS SC SE SP TO {

import delimited "${rawdata}/mayors data/consulta_cand_2012_`state'.txt", delimiter(";") clear 

* mayors
keep if v9==11

* elected
keep if v42==1

* we keep only the variables that we use in the analysis (or data cleaning)
rename v7 id_tse
rename v19 party_mayor
rename v30 code_gender_mayor
rename v31 gender_mayor
rename v32 code_educ_mayor
rename v33 educ_mayor

keep id_tse party_mayor code_gender_mayor gender_mayor code_educ_mayor educ_mayor v5 v11 v14

save "${rawdata}/mayors data/temp/mayordata`state'12.dta", replace

}

* appending data
use "${rawdata}/mayors data/temp/mayordataAC12.dta"

foreach state in AL AM AP BA CE ES GO MA MG MS MT PA PB PE PI PR RJ RN RO RR RS SC SE SP TO {

append using "${rawdata}/mayors data/temp/mayordata`state'12.dta"

}

rename id_tse id_municipio_tse
// there are municipalities that by different reasons had more than one election in 2012 or had judicial complaints. We will manually correct
// in lines 298-330 the information considering whether the 2016 elected mayor is the same or not to the 2012 mayor observations. 
// That is, if 2016 mayor is different to the observations of the 2012 election, we do not correct the info regarding the winner of 2012 election 
// and we drop one of the two 2012 observations. 
// If 2016 mayor is the same to any of the two observations of the 2012 election, we do manually correct the info considering the available
// information that we had before the experiment took place (October-Nov 2016). 
// In addition, we correct other inconsistencies regarding the possibility of running for another term
// We do all these corrections only for the sample municipalities that we use in the data analysis
bysort id_municipio_tse: egen count_id_tse_2012=count(id_municipio_tse)
merge m:m id_municipio_tse using "${rawdata}/municipalities/officialids.dta", keepusing(id_municipio)
drop _merge
rename id_municipio cod_ibge
replace cod_ibge = floor(cod_ibge/10)
rename v14 cpf_mayor_2012 // the cpf is a unique official identifier of an individual

* we keep only the variables that we use in the analysis (or data cleaning)
order cod_ibge v11 cpf_mayor_2012 count_id_tse id_municipio_tse
keep cod_ibge v11 cpf_mayor_2012 count_id_tse id_municipio_tse

save "${rawdata}/mayors data/temp/mayor_2012_temp.dta", replace

* we merge the 2012 election data with the 2016 election data
use "${rawdata}/mayors data/temp/policyexperiment_mayor_char_temp.dta", clear
merge m:m cod_ibge using "${rawdata}/mayors data/temp/mayor_2012_temp.dta"
drop _merge

* we define mayor term inf office
gen mandate2_mayor=1 if cpf_mayor==cpf_mayor_2012&cpf_mayor!=.&cpf_mayor_2012!=.
replace mandate2_mayor=0 if cpf_mayor!=cpf_mayor_2012&cpf_mayor!=.&cpf_mayor_2012!=.

// we now manually correct the information considering the 2012 mayors.
bysort cod_ibge: egen sum_mandate2_mayor=sum(mandate2_mayor) if count_id_tse_2012>1
drop if (cod_ibge[_n]==cod_ibge[_n+1])&sum_mandate2_mayor==0

replace mandate2_mayor=0 if cod_ibge==220020
drop if mandate2_mayor==1&cod_ibge==230130
replace mandate2_mayor=0 if cod_ibge==251650
drop if mandate2_mayor==0&cod_ibge==260040
replace mandate2_mayor=0 if cod_ibge==280590
replace mandate2_mayor=0 if cod_ibge==280680
replace mandate2_mayor=0 if cod_ibge==315720
drop if mandate2_mayor==1&cod_ibge==320016
drop if mandate2_mayor==1&cod_ibge==410290
replace mandate2_mayor=0 if cod_ibge==412230
drop if mandate2_mayor==1&cod_ibge==412240
replace mandate2_mayor=0 if cod_ibge==412300
replace mandate2_mayor=0 if cod_ibge==412480
replace mandate2_mayor=0 if cod_ibge==420330
replace mandate2_mayor=0 if cod_ibge==421050
replace mandate2_mayor=0 if cod_ibge==421270
drop if mandate2_mayor==0&cod_ibge==422000
drop if mandate2_mayor==0&cod_ibge==430150
replace mandate2_mayor=0 if cod_ibge==430230
drop if mandate2_mayor==1&cod_ibge==430600
replace mandate2_mayor=0 if cod_ibge==431405
replace mandate2_mayor=0 if cod_ibge==431470
drop if mandate2_mayor==1&cod_ibge==432070
replace mandate2_mayor=0 if cod_ibge==432080
replace mandate2_mayor=0 if cod_ibge==510720
drop if mandate2_mayor==0&cod_ibge==520790

order cod_ibge male_mayor age_mayor college_mayor mandate2_mayor party_left_mayor party_mayor
drop id_municipio_tse-sum_mandate2_mayor
bysort cod_ibge: egen count_cod_ibge=count(cod_ibge)
drop if count_cod_ibge==2
drop count_cod_ibge

label var cod_ibge "Municipality official id" // Source: IBGE
label var male_mayor "Male - Mayor" // Source: Tribunal Superior Eleitoral (Elections 2016)
label var age_mayor "Age - Mayor" // Source: Tribunal Superior Eleitoral (Elections 2016)
label var college_mayor "College or more - Mayor" // Source: Tribunal Superior Eleitoral (Elections 2016)
label var mandate2_mayor "2nd Term - Mayor" // Source: Tribunal Superior Eleitoral (Elections 2016 and 2012)
label var party_left_mayor "Leftist Political Party - Mayor" // Source: Own based on Tribunal Superior Eleitoral (Elections 2016) and historical political platforms
label var party_mayor "Political Party - Mayor" // Source: Own based on Tribunal Superior Eleitoral (Elections 2016)

save "${rawdata}/clean data/policyexperiment_mayor_char.dta", replace  


***********************************
*********** TAX DATA **************
***********************************
clear all
import delimited "${rawdata}/tax revenues/all.tax.revenues_2010_2015.csv"

rename recorcamentaria total_revenues
rename rectributaria total_tax_revenues

gen share_taxes=total_tax_revenues/total_revenues
* mean share of tax revenues
bysort cod_ibge: egen share_taxes_2010_2015=mean(share_taxes)
collapse (mean) share_taxes_2010_2015, by(cod_ibge)
label var share_taxes_2010_2015 ""

label var cod_ibge "Municipality official id" // Source: IBGE
label var share_taxes_2010_2015 "Local Tax Revenues (2010-2015)" // Source: FINBRA (Finanças Municipais) Brasil 2010-2015

save "${rawdata}/clean data/tax_revenues.dta", replace 

*****************************************
********** MUNICIPAL FINANCES ***********
*****************************************

// Revenues
import delimited "${rawdata}/finances/finbra - receitas.csv", delimiter(";") varnames(4) rowrange(5) clear 

keep if coluna == "Receitas Brutas Realizadas"

keep codibge população coluna conta valor

destring valor, dpcomma replace

rename codibge cod_ibge
rename população population

split conta, p(" - ")
rename conta1 conta_str
drop conta2-conta4

gen revenues = "."
replace revenues = "total" if conta_str == "Total Receitas"

replace revenues = "tax_total" if conta_str == "1.1.1.0.00.00.00"
replace revenues = "tax_iptu" if conta_str == "1.1.1.2.02.00.00"
replace revenues = "tax_itbi" if conta_str == "1.1.1.2.08.00.00"
replace revenues = "tax_iss" if conta_str == "1.1.1.3.05.00.00"
replace revenues = "tax_other" if conta_str == "1.1.1.2.01.00.00" | conta_str == "1.1.1.2.04.00.00"

replace revenues = "transfer_total" if conta_str == "1.7.2.0.00.00.00"
replace revenues = "trans_central" if conta_str == "1.7.2.1.00.00.00"
replace revenues = "trans_central_fpm" if conta_str == "1.7.2.1.01.00.00"
replace revenues = "trans_state" if conta_str == "1.7.2.2.00.00.00"
replace revenues = "trans_other" if conta_str == "1.7.2.3.00.00.00" | conta_str == "1.7.2.4.00.00.00"

replace revenues = "rev_other" if conta_str == "1.1.2.0.00.00.00" | conta_str == "1.1.3.0.00.00.00" | conta_str == "1.2.0.0.00.00.00" | conta_str == "1.3.0.0.00.00.00" |conta_str == "1.4.0.0.00.00.00" | conta_str == "1.5.0.0.00.00.00" | conta_str == "1.6.0.0.00.00.00"  | conta_str == "1.7.3.0.00.00.00" | conta_str == "1.7.4.0.00.00.00" | conta_str == "1.7.5.0.00.00.00" | conta_str == "1.7.6.0.00.00.00" | conta_str == "1.7.7.0.00.00.00" | conta_str == "1.9.0.0.00.00.00" | conta_str == "2.0.0.0.00.00.00" | conta_str == "7.0.0.0.00.00.00" | conta_str == "8.0.0.0.00.00.00"
drop if revenues == "."

collapse (sum) valor, by(cod_ibge population revenues)

gen total = valor if revenues == "total"
egen total_rev = total(total), by(cod_ibge)
format valor total_rev %12.0f
drop total

gen share = valor/total_rev*100
gen valor_pc = valor/population
gen valorpc_usd = valor_pc/3.3540 	 //Source: https://fred.stlouisfed.org/series/DEXBZUS#0
format share valorpc_usd %12.2f

keep cod_ibge revenues share valorpc_usd

label var cod_ibge "Municipality official id" // Source: IBGE
label var revenues "Revenue Categories" // Source: IBGE
label var share "Share out of Total Revenue" // Source: IBGE
label var valorpc_usd "Revenue per capita in USD" // Source: IBGE

save "${rawdata}/clean data/revenues.dta", replace

// Expenditures

import delimited "${rawdata}/finances/finbra - despesas por funcao.csv", delimiter(";") varnames(4) rowrange(5) clear 

keep if coluna == "Despesas Liquidadas"

destring valor, dpcomma replace

split conta, p(" - ")
rename conta1 conta_str
drop conta2

gen expenses = "."
replace expenses = "total" if conta == "Despesas (Exceto Intraorçamentárias)"
replace expenses = "administration" if conta == "04 - Administração"
replace expenses = "health" if conta == "10 - Saúde"
replace expenses = "education" if conta == "12 - Educação"
replace expenses = "urban" if conta == "15 - Urbanismo"
replace expenses = "sanitation" if conta == "17 - Saneamento"
replace expenses = "transport" if conta == "26 - Transporte"
replace expenses = "other" if conta_str == "01" | conta_str == "02" | conta_str == "03" | conta_str == "05" | conta_str == "06" | conta_str == "07" | conta_str == "08" | conta_str == "09" | conta_str == "11" | conta_str == "13" | conta_str == "14" | conta_str == "16" | conta_str == "18" | conta_str == "19" | conta_str == "20" | conta_str == "21" | conta_str == "22" | conta_str == "23" | conta_str == "24" | conta_str == "25" | conta_str == "27" | conta_str == "28"
drop if expenses == "."

rename codibge cod_ibge
rename população population

collapse (mean) population (sum) valor, by(cod_ibge expenses)

gen total = valor if expenses == "total"
format valor total %12.0f
egen total_exp = total(total), by(cod_ibge)
drop total

format total_exp %12.0f
gen share = valor/total_exp*100
gen valor_pc = valor/population
gen valorpc_usd = valor_pc/3.3540 	 //Source: https://fred.stlouisfed.org/series/DEXBZUS#0
format share valorpc_usd %12.2f

keep cod_ibge share expenses valorpc_usd

label var cod_ibge "Municipality official id" // Source: IBGE
label var expenses "Expenses Categories" // Source: IBGE
label var share "Share out of Total Expenses" // Source: IBGE
label var valorpc_usd "Expenses per capita in USD" // Source: IBGE

save "${rawdata}/clean data/expenditures.dta", replace

**********************************************
********** GOVERNMENT SURVEY DATA ************
**********************************************

*2015 data
import excel "${rawdata}/munic survey/Base_MUNIC_2015.xls", sheet("Recursos para gestão") firstrow clear

tostring A1, gen(cod_ibge) 
replace cod_ibge = substr(cod_ibge, 1, 6)
destring cod_ibge, replace

keep cod_ibge A64 A69

rename A64 iptu
rename A69 cad_issqn

foreach var in "iptu" "cad_issqn" {

rename `var' `var'_2
gen `var' = . 
replace `var' = 1 if `var'_2 == "Sim"
replace `var' = 0 if `var'_2 == "Não"
drop `var'_2
}

foreach var in "iptu" "cad_issqn" {
rename `var' `var'_2015
}

keep cod_ibge iptu_2015 cad_issqn_2015 

label var iptu_2015 "Property Tax - existence (2015)" //Source: IBGE MUNIC 2015
label var cad_issqn_2015 "ISS Tax - existence (2015)" //Source: IBGE MUNIC 2015

save "${rawdata}/clean data/munic_survey.dta", replace 

